package com.xgst.land.activity

import android.content.Context
import android.graphics.Color
import android.view.Gravity
import androidx.lifecycle.ViewModelProvider
import com.blankj.utilcode.util.LogUtils
import com.blankj.utilcode.util.SPStaticUtils
import com.blankj.utilcode.util.ToastUtils
import com.githang.statusbar.StatusBarCompat
import com.gym.baselib.base.BaseActivity
import com.hjq.http.EasyConfig
import com.ht.medicaltreatment.base.CacheKey
import com.scwang.smart.refresh.footer.ClassicsFooter
import com.scwang.smart.refresh.header.ClassicsHeader
import com.scwang.smart.refresh.layout.SmartRefreshLayout
import com.scwang.smart.refresh.layout.api.RefreshFooter
import com.scwang.smart.refresh.layout.api.RefreshLayout
import com.scwang.smart.refresh.layout.listener.DefaultRefreshFooterCreator
import com.xgst.land.R
import com.xgst.land.databinding.ActivitySplashLayoutBinding
import com.xgst.land.viewmodel.LoginViewModel

class SplashActivity : BaseActivity<ActivitySplashLayoutBinding>() {

    override fun viewBinding(): ActivitySplashLayoutBinding {
        return ActivitySplashLayoutBinding.inflate(layoutInflater)
    }

    override fun getLayoutId() = R.layout.activity_splash_layout

    override fun init() {
        StatusBarCompat.setTranslucent(window,true)
        initRefresh()
        initSDK()

        val token = SPStaticUtils.getString(CacheKey.TOKEN)
        if(token == ""){
            startActivity(LoginActivity::class.java)
            finish()
        }else{
            EasyConfig.getInstance().addHeader("Mobile-Custom-Token",token)
            startActivity(MainActivity::class.java)
            finish()
        }
    }

    private fun initSDK() {
        ToastUtils.getDefaultMaker()
            .setBgColor(Color.BLACK)
            .setTextColor(Color.WHITE)
            .setGravity(Gravity.CENTER,0,0)
    }

    private fun initRefresh() {
        SmartRefreshLayout.setDefaultRefreshHeaderCreator { context, layout ->
            layout.setPrimaryColors(Color.RED)
            val classHeaderCreator = ClassicsHeader(context)
            classHeaderCreator.setPrimaryColor(getColor(R.color.blueDeep))
            classHeaderCreator.setAccentColorId(R.color.white)
            classHeaderCreator
        }

        SmartRefreshLayout.setDefaultRefreshFooterCreator(object : DefaultRefreshFooterCreator {
            override fun createRefreshFooter(
                context: Context,
                layout: RefreshLayout
            ): RefreshFooter {
                layout.setPrimaryColorsId(R.color.black)
                layout.setEnableAutoLoadMore(false)
                layout.setEnableLoadMore(false)
                return ClassicsFooter(context)
            }
        })
    }
}